package edu.thu.studio.ormdesigner.editor.contributor;

import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.gef.ui.actions.ZoomComboContributionItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;

import edu.thu.studio.ormdesigner.editor.ORMGraphicalEditor;

public class ORMModelMultiPageEditorActionBarContributor extends MultiPageEditorActionBarContributor {
    
    private ZoomComboContributionItem zoomComboContributionItem;
    
    @Override
    public void setActivePage(IEditorPart activeEditor) {
        IActionBars actionBars = this.getActionBars();
        
        actionBars.clearGlobalActionHandlers();
        actionBars.getToolBarManager().removeAll();
        
        ORMGraphicalEditor editor = (ORMGraphicalEditor) activeEditor;
        
        ORMModelActionBarContributor activeContributor = editor.getActionBarContributor();
        
        if (this.zoomComboContributionItem == null) {
            this.zoomComboContributionItem = new ZoomComboContributionItem(this.getPage());
        }
        
        activeContributor.setActiveEditor(editor);
        
        activeContributor.contributeToToolBar(actionBars.getToolBarManager(), this.zoomComboContributionItem);
        
        ZoomComboContributionItem item = (ZoomComboContributionItem) getActionBars().getToolBarManager().find(
            GEFActionConstants.ZOOM_TOOLBAR_WIDGET);
        if (item != null) {
            ZoomManager zoomManager = (ZoomManager) editor.getAdapter(ZoomManager.class);
            item.setZoomManager(zoomManager);
        }
        
        actionBars.updateActionBars();
        
    }
    
}
